package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.SftTrafficAccident;
import com.ruoyi.bussiness.service.ISftTrafficAccidentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 交通事故Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/accident")
public class SftTrafficAccidentController extends BaseController
{
    private String prefix = "bussiness/accident";

    @Autowired
    private ISftTrafficAccidentService sftTrafficAccidentService;

    @RequiresPermissions("bussiness:accident:view")
    @GetMapping()
    public String accident()
    {
        return prefix + "/accident";
    }

    /**
     * 查询交通事故列表
     */
    @RequiresPermissions("bussiness:accident:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SftTrafficAccident sftTrafficAccident)
    {
        startPage();
        List<SftTrafficAccident> list = sftTrafficAccidentService.selectSftTrafficAccidentList(sftTrafficAccident);
        return getDataTable(list);
    }

    /**
     * 导出交通事故列表
     */
    @RequiresPermissions("bussiness:accident:export")
    @Log(title = "交通事故", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SftTrafficAccident sftTrafficAccident)
    {
        List<SftTrafficAccident> list = sftTrafficAccidentService.selectSftTrafficAccidentList(sftTrafficAccident);
        ExcelUtil<SftTrafficAccident> util = new ExcelUtil<SftTrafficAccident>(SftTrafficAccident.class);
        return util.exportExcel(list, "交通事故数据");
    }

    /**
     * 新增交通事故
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存交通事故
     */
    @RequiresPermissions("bussiness:accident:add")
    @Log(title = "交通事故", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SftTrafficAccident sftTrafficAccident)
    {
        return toAjax(sftTrafficAccidentService.insertSftTrafficAccident(sftTrafficAccident));
    }

    /**
     * 修改交通事故
     */
    @RequiresPermissions("bussiness:accident:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SftTrafficAccident sftTrafficAccident = sftTrafficAccidentService.selectSftTrafficAccidentById(id);
        mmap.put("sftTrafficAccident", sftTrafficAccident);
        return prefix + "/edit";
    }

    /**
     * 修改保存交通事故
     */
    @RequiresPermissions("bussiness:accident:edit")
    @Log(title = "交通事故", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SftTrafficAccident sftTrafficAccident)
    {
        return toAjax(sftTrafficAccidentService.updateSftTrafficAccident(sftTrafficAccident));
    }

    /**
     * 删除交通事故
     */
    @RequiresPermissions("bussiness:accident:remove")
    @Log(title = "交通事故", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sftTrafficAccidentService.deleteSftTrafficAccidentByIds(ids));
    }
}
